package com.project.controller;

import com.alibaba.fastjson.JSONObject;
import com.project.bean.OrderBean;
import com.project.bean.ReturnOrder;
import com.project.dto.UserOrderRefundEntity;
import com.project.dto.UserOrderRefundRecordEntity;
import com.project.service.IOrderService;
import com.project.service.IReturnOrderService;
import com.project.util.SnowIdUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("returnOrder")
public class ReturnOrderController {
      @Autowired
      private IReturnOrderService service;
      @Autowired
      RabbitTemplate rabbitTemplate;
      @Autowired
      private  IOrderService orderService;
      @RequestMapping("addReturnOrder")
      public String addReturnOrder(String orderNum,String modeOfPayment,String reason){
            ReturnOrder returnOrder=new ReturnOrder();
            returnOrder.setReturnOrderNum(SnowIdUtils.uniqueLong());
            returnOrder.setOrderNum(orderNum);
            returnOrder.setReason(reason);
            returnOrder.setModeOfPayment(modeOfPayment);
            service.updateOrderStatus(returnOrder);
            //发送给后端审核
            UserOrderRefundEntity userOrderRefundEntity=new UserOrderRefundEntity();
            userOrderRefundEntity.setOrderRef(returnOrder.getOrderNum());
            userOrderRefundEntity.setRefundRef(returnOrder.getReturnOrderNum());
            userOrderRefundEntity.setReason(reason);
            String jsonString = JSONObject.toJSONString(userOrderRefundEntity);
            rabbitTemplate.convertAndSend("webOne","returnOrder",jsonString);
            return "ok";
      }
}
